package com.msstudio;

// Decompiled by Jad v1.5.7g. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi 

import com.msstudio.utils.PkgTools;
import com.msstudio.utils.HttpPosterListener;
import com.msstudio.midlets.MSCMIDlet;
import javax.microedition.lcdui.*;

public class AckSvrMsg
    implements CommandListener, HttpPosterListener
{//Ӧ���������Ϣ��

    protected Command cmdGetInfor;
    protected Command cmdAdd;
    protected Command cmdAgree;
    protected Command cmdRefuse;
    protected Command cmdBack;
    protected Command cmdBackToForm;
    protected Command cmdCancel;
    private Form form1;
    private String sUIN;
    private TextBox inputBox;
    private Command cmdOkToSend;
    private boolean bInited;

    public AckSvrMsg()
    {
        cmdGetInfor = null;
        cmdAdd = null;
        cmdAgree = null;
        cmdRefuse = null;
        cmdBack = null;
        cmdBackToForm = null;
        cmdCancel = null;
        form1 = null;
        sUIN = null;
        bInited = false;
    }

    public void init()
    {
        cmdGetInfor = new Command(MSCMIDlet.multiLang.sGetInfor, 1, 2);
        cmdAdd = new Command(MSCMIDlet.multiLang.sAddToFriendList, 1, 2);
        cmdAgree = new Command(MSCMIDlet.multiLang.sAgree, 1, 1);
        cmdRefuse = new Command(MSCMIDlet.multiLang.sRefuse, 1, 1);
        cmdBack = new Command(MSCMIDlet.multiLang.sCancel, 2, 3);
        cmdBackToForm = new Command(MSCMIDlet.multiLang.sCancel, 2, 3);
        cmdCancel = new Command(MSCMIDlet.multiLang.sBack, 2, 3);
        form1 = new Form(MSCMIDlet.multiLang.sSystemMessage);
        form1.addCommand(cmdBack);
        form1.setCommandListener(this);
    }

    public void show(int i, String s, String s1)
    {
        if(!bInited)
        {
            init();
            bInited = true;
        }
        switch(i)
        {
        case 1: // '\001'
            sUIN = s;
            form1.append(MSCMIDlet.multiLang.MakeCombineMsg(MSCMIDlet.multiLang.sAddUFriend, s));
            form1.addCommand(cmdGetInfor);
            form1.addCommand(cmdAdd);
            MSCMIDlet.display.setCurrent(form1);
            break;

        case 2: // '\002'
            sUIN = s;
            form1.append(MSCMIDlet.multiLang.GetCombineMsg(15, s) + "\n" + s1);
            form1.addCommand(cmdAgree);
            form1.addCommand(cmdRefuse);
            form1.addCommand(cmdGetInfor);
            form1.addCommand(cmdAdd);
            MSCMIDlet.display.setCurrent(form1);
            break;

        case 3: // '\003'
            MSCMIDlet.instance.showMessage(MSCMIDlet.multiLang.sSystemMessage, MSCMIDlet.multiLang.GetCombineMsg(64, s), this, cmdCancel, null);
            break;

        case 4: // '\004'
            MSCMIDlet.instance.showMessage(MSCMIDlet.multiLang.sSystemMessage, MSCMIDlet.multiLang.GetCombineMsg(105, s) + "\n" + s1, this, cmdCancel, null);
            break;
        }
    }

    public void commandAction(Command command, Displayable displayable)
    {
        if(command == cmdAdd)
        {
            form1.removeCommand(cmdAdd);
            MSCMIDlet.addFriend.show(form1, sUIN);
            return;
        }
        if(command == cmdGetInfor)
        {
            MSCMIDlet.finger.doGetInfor(sUIN, form1);
            return;
        }
        if(command == cmdAgree)
        {
            form1.removeCommand(cmdAgree);
            form1.removeCommand(cmdRefuse);
            MSCMIDlet.httpPoster.ackAddFriend(sUIN, "0", "", this);
            return;
        }
        if(command == cmdRefuse)
        {
            inputBox = new TextBox(MSCMIDlet.multiLang.sAttachMessage, "", 40, 0);
            cmdOkToSend = new Command(MSCMIDlet.multiLang.sYes, 1, 1);
            inputBox.addCommand(cmdOkToSend);
            inputBox.addCommand(cmdBackToForm);
            inputBox.setCommandListener(this);
            MSCMIDlet.display.setCurrent(inputBox);
            return;
        }
        if(command == cmdBack)
        {
            MSCMIDlet.mainForm.show();
            MSCMIDlet.finger.cancelPre(form1);
            PkgTools.EmptyForm(form1);
            form1.removeCommand(cmdAdd);
            form1.removeCommand(cmdAgree);
            form1.removeCommand(cmdGetInfor);
            form1.removeCommand(cmdRefuse);
            return;
        }
        if(command == cmdBackToForm)
        {
            MSCMIDlet.display.setCurrent(form1);
            return;
        }
        if(command == cmdCancel)
        {
            MSCMIDlet.mainForm.show();
            return;
        }
        try
        {
            if(command == cmdOkToSend)
            {
                String s = inputBox.getString();
                MSCMIDlet.httpPoster.ackAddFriend(sUIN, "1", PkgTools.Encodecgi(s), this);
                form1.removeCommand(cmdAgree);
                form1.removeCommand(cmdRefuse);
                MSCMIDlet.display.setCurrent(form1);
                return;
            }
        }
        catch(Exception exception) { }
        return;
    }

    public void receiveHttpResponse(String s)
    {
        String s1 = PkgTools.GetParaVal("CMD", s).toUpperCase();
        String s2 = PkgTools.GetParaVal("RES", s);
        if(s1.length() == 0 || s2.equals("3"))
        {
            MSCMIDlet.instance.showAlert(MSCMIDlet.multiLang.sMSC, MSCMIDlet.multiLang.sTimeOut, null);
            return;
        } else
        {
            MSCMIDlet.friendList.showInfor(MSCMIDlet.multiLang.sSended);
            return;
        }
    }

    public void handleHttpError(String s)
    {
        MSCMIDlet.instance.showAlert(MSCMIDlet.multiLang.sMSC, MSCMIDlet.multiLang.sWrong, null);
    }
}
